

package com.example.administrator.caigou51.recyclerCard.cardView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.administrator.caigou51.EventBusClass.UpdateOrdeListTopTitle;
import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.activity.OrderListActivity;
import com.example.administrator.caigou51.recyclerCard.basic.CardItemView;
import com.example.administrator.caigou51.recyclerCard.basic.MaterialListAdapter;
import com.example.administrator.caigou51.recyclerCard.card.OrderTypeCard;

import de.greenrobot.event.EventBus;


public class OrderTypeCardView extends CardItemView<OrderTypeCard> implements View.OnClickListener{
 	private Context mContext;
    ImageView imageViewLine;
    TextView textViewTitle;
    OrderTypeCard card;

    public OrderTypeCardView(Context context) {
        super(context);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public OrderTypeCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public OrderTypeCardView(Context context,
                             AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    @Override
    public void build(OrderTypeCard card) {
        // TODO Auto-generated method stub
        super.build(card);
        this.card=card;
        setOnClickListener(this);
        imageViewLine= (ImageView) findViewById(R.id.imageViewLine);
        textViewTitle= (TextView) findViewById(R.id.textViewTitle);
      //  getLayoutParams().width=App.getInstance().screenWidth/4;
        if (card.isChecked())
        {
            imageViewLine.setVisibility(VISIBLE);
            textViewTitle.setTextColor(getResources().getColor(R.color.color_1ca146));
        }
        else
        {
            imageViewLine.setVisibility(INVISIBLE);
            textViewTitle.setTextColor(getResources().getColor(R.color.color_333333));
        }

        if (card.getOrderInfoBean().getStatus().equals(OrderListActivity.DFK+""))
        {
            textViewTitle.setText("待付款");
        }else if (card.getOrderInfoBean().getStatus().equals(OrderListActivity.DFH+""))
        {
            textViewTitle.setText("待发货");
        }else if (card.getOrderInfoBean().getStatus().equals(OrderListActivity.DSH+""))
        {
            textViewTitle.setText("待收货");
        }else if (card.getOrderInfoBean().getStatus().equals(OrderListActivity.JYWG+""))
        {
            textViewTitle.setText("已完成");
        }else if (card.getOrderInfoBean().getStatus().equals(OrderListActivity.YQX_1+"") || card.getOrderInfoBean().getStatus().equals(OrderListActivity.YQX_2+""))
        {
            textViewTitle.setText("已取消");
        }else if (card.getOrderInfoBean().getStatus().equals(OrderListActivity.ALL+""))
        {
            textViewTitle.setText("全部订单");
        }else if (card.getOrderInfoBean().getStatus().equals(OrderListActivity.HDFK+""))
        {
            textViewTitle.setText("货到付款");
        }

        //setScaled(false);
    }

    @Override
    public void onClick(View v) {
        UpdateOrdeListTopTitle updateOrdeListTopTitle=new UpdateOrdeListTopTitle();
        if (card.isAllOrder()) {
            updateOrdeListTopTitle.setAllOrder(true);
        }else
        {
            updateOrdeListTopTitle.setOrderInfoBean(card.getOrderInfoBean());
        }
            EventBus.getDefault().post(updateOrdeListTopTitle);
            MaterialListAdapter materialListAdapter = ((MaterialListAdapter) (card.getMaterialListView().getAdapter()));
            for (int i = 0; i < materialListAdapter.getAllList().size(); i++) {
                OrderTypeCard orderTypeCard = (OrderTypeCard) materialListAdapter.getAllList().get(i);
                orderTypeCard.setChecked(false);
            }
            card.setChecked(true);
            materialListAdapter.notifyDataSetChanged();

    }
}
